<template>
	<div class="wrap">
		<!-- 搜索 -->
		<SearchNavHead v-model:searchByIdName="searchByIdName">
			<template #reset>
				<el-button class="btn" @click="resetSearchByIdName">重置</el-button>
			</template>
		</SearchNavHead>

		<StudentsAdminTable :stu="stu" :total="total" @change="handleChange" />
	</div>
</template>

<script setup>
import SearchNavHead from '@/components/mod/SearchNavHead.vue'
import StudentsAdminTable from '@/components/domi_admin/StudentsAdminTable.vue'
import { useUserStore } from '@/stores/userStore';
import { getStu } from '@/utils/axios/domiRequests';
import { getStuOneBuild } from '@/utils/axios/getTotal';
import { reactive, ref, watch } from 'vue'

const {userInfo} =useUserStore()
const total = ref(0)
const stu = ref()

const searchByIdName = reactive({
	stuId: '',
	stuName: '',
	flag: 1, //表示搜索学生信息
})
watch(
	() => searchByIdName.stu,
	(newVal) => {
		stu.value = newVal
		total.value = stu.value?.length
	}
)

async function resetSearchByIdName() {
  let {data}=await getStu({currentPage:1,buildId:userInfo.buildId,pageSize:10})
  let res=await getStuOneBuild({buildId:userInfo.buildId})
  stu.value=data
  total.value=res.data
  Object.assign(searchByIdName,{stuId:"",stuName:""})
}

// 自定义事件
const handleChange = ({ data, tota }) => {
	stu.value = data
	total.value = tota ? tota : 0
}
</script>

<style scoped lang="scss">
.btn {
	background: rgb(0, 202, 237);
	color: #ffff;
}
</style>
